﻿using DevExpress.XtraGrid.Demos.util;
using Luna小店.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Luna小店.UC.面料库存.门户UC.service
{
    public class 面料门户Service
    {
        /// <summary>
        /// 调用webService取待领订单list
        /// </summary>
        /// <returns></returns>
        public static List<DTO待领料订单> get待领料订单List()
        {
            return 
                FunctionHelper.JsonDeserialization<List<DTO待领料订单>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/inventory/getOrderStockOutApplyMaterialAll"
                        )
                    );
        }

        /// <summary>
        /// 调用webService取出入库申请list
        /// </summary>
        /// <returns></returns>
        public static List<DTO出入库申请> get出入库申请List()
        {
            return 
                FunctionHelper.JsonDeserialization<List<DTO出入库申请>>(
                    RestCall.httpGetMethod(URL.接口url + "/inventory/getApplyIndexByType"
                    )
                );
        }
    }

    /// <summary>
    /// 待领料订单DTO
    /// </summary>
    public class DTO待领料订单
    {
        public String id { get; set; }
        public String stockOutApplyDate { get; set; } //  出库申请日期索引，yyyyMMdd
        public String orderTypeId { get; set; } //  订单类型id
        public String orderTypeName { get; set; }   //  订单类型名称
        public String orderCustomerTypeId { get; set; }  //  订单客户类型id
        public String orderCustomerTypeName { get; set; }  //  订单客户类型名称
        public String orderId { get; set; } //  订单id
        public String orderNo { get; set; } //  订单号
        public String materialCode { get; set; }    //  物料编码
        public Double quantity { get; set; }    //  需求数量
        public Boolean reject { get; set; }//  是否驳回
        public DTO待领料订单()
        {
            this.reject = false;
        }
    }
    /// <summary>
    /// 出入库申请DTO
    /// </summary>
    public class DTO出入库申请
    {
        public String applyType { get; set; }   //  需求类型
        public int applyBillCount { get; set; } //  需求单数量
        public Dictionary<String, Double> quantitySum { get; set; } = new Dictionary<string, double>();    //  物料合计数,K:物料编码    V:数量合计

        public DTO出入库申请()
        {

        }

    }
    /// <summary>
    /// 出入库申请的前五DTO
    /// </summary>
    public class DTO物料需求
    {
        public String applyType { get; set; }   //  需求类型
        public int applyBillCount { get; set; } //  需求单数量
        public String code1 { get; set; }
        public String code2 { get; set; }
        public String code3 { get; set; }
        public String code4 { get; set; }
        public String code5 { get; set; }
        public String quantity1 { get; set; }
        public String quantity2 { get; set; }
        public String quantity3 { get; set; }
        public String quantity4 { get; set; }
        public String quantity5 { get; set; }
        public DTO物料需求()
        {

        }
        public DTO物料需求(DTO出入库申请 DTO出入库申请)
        {
            this.applyType = DTO出入库申请.applyType;
            this.applyBillCount = DTO出入库申请.applyBillCount;
            List<String> codes = new List<string>();
            List<Double> quantities = new List<double>();
            foreach (KeyValuePair<String, Double> keyValue in DTO出入库申请.quantitySum)
            {
                codes.Add(keyValue.Key);
                quantities.Add(keyValue.Value);
            }

            try
            {
                this.code1 = codes[0];
                this.quantity1 = quantities[0].ToString();
            }
            catch { }
            try
            {
                this.code2 = codes[1];
                this.quantity2 = quantities[1].ToString();
            }
            catch { }
            try
            {
                this.code3 = codes[2];
                this.quantity3 = quantities[2].ToString();
            }
            catch { }
            try
            {
                this.code4 = codes[3];
                this.quantity4 = quantities[3].ToString();
            }
            catch { }
            try
            {
                this.code5 = codes[4];
                this.quantity5 = quantities[4].ToString();
            }
            catch { }
        }
    }
}
